/**
 * Created by Administrator on 2017/5/22.
 */

// function switchanguage(obj) {
// 	var tempData = obj.data;
// 	console.log(tempData.name)
// 	for(var name in tempData)
// 	{
// 		var lang = ff.util.getLang(name);
// 		if(null != lang)
// 		{
// 			obj.data[name] = lang;
// 		}
// 	}
// 	return obj.data;
// }
var hostName = location.hostname;
var basePath = (hostName == "192.168.5.131") ? "http://adel-site-war.adellock.com/adel-site-war-web/" : "http://adel-site-war.adellock.com/adel-site-war-web/";
var baseSearchUrl = 'http://192.168.5.131:8081/adel/page/'; //'http://app-client.adellock.com/app-client-web/adel/page/';//跳到商城搜索列表页面的地址
var enddo = ".do";
var imgBasePath = "http://image.adellock.com";
function spliceImgUrl(url) {
    return imgBasePath + url.replace("_size", "_origin");
}

var head_nav = avalon.define({
    $id: 'headNav',
    navList: []
})

getNavList();
var navListRight=false;
function getNavList() {
    var _basePath = basePath + 'pageTab' + enddo;
    var bookmarkIdArr = [];
    console.log(_basePath);
    $.frontEngineAjax.ajaxRequest(function (data) {
        head_nav.navList = data;
        var tempOption;
        for (var i = 0, len = data.length; i < len; i++) {
            tempOption = {
                "name": data[i].name,
                "id": data[i].id
            }
            bookmarkIdArr[i] = tempOption;
        }
        if (window.sessionStorage) {
            var session = window.sessionStorage;
            var str = JSON.stringify(bookmarkIdArr)
            session.setItem("pageId", str);
            navListRight = true;
        } else {
            console.log('This browser does NOT support localStorage');
        }
        console.log("success...." + bookmarkIdArr[1].sort)
    }, _basePath);
}

function getPageId(sort) {
    var sessionStorage = window.sessionStorage;
    var bookmarkId = JSON.parse(sessionStorage.getItem('pageId'));
    console.log(bookmarkId);
    console.log(bookmarkId[1].name);
    var currPageId = '';
    for (var k in bookmarkId) {
        console.log(bookmarkId[1].name)
        if (sort == bookmarkId[k].name) {
            currPageId = bookmarkId[k].id;
        }
    }
    return currPageId;
}

function getServiceColumnId(sort) {
    var sessionStorage = window.sessionStorage;
    var columnId = JSON.parse(sessionStorage.getItem('serviceColumnId'));
    console.log(columnId[1].name);
    var currPageId = '';
    for (var k in columnId) {
        console.log(columnId[1].name)
        if (sort == columnId[k].name) {
            currPageId = columnId[k].id;
        }
    }
    return currPageId;
}

function getCatelogUrl(id) {//获取栏目ID
    var _basePath = basePath + 'catelog/' + id + enddo;
    return _basePath;
}

function getDataUrl(id) {//获取栏目数据
    var _basePath = basePath + 'data/' + id + enddo;
    return _basePath;
}

function getChildUrl(id) {//获取栏目数据
    var _basePath = basePath + 'child/' + id + enddo;
    return _basePath;
}

function getDataviewUrl(id) {//获取单个数据内容的具体数据
    var _basePath = basePath + 'dataview/' + id + enddo;
    return _basePath;
}

function conformName(str) {//格式化name
    var name = str.split("-")[1];
    return name;
}

function session_Storage(name, str) {//session本地存储
    if (window.sessionStorage) {
        var session = window.sessionStorage;
        var _str = JSON.stringify(str)
        session.setItem(name, _str);
        console.log(session.getItem(name));
    } else {
        console.log('This browser does NOT support localStorage');
    }
}

function get_Storage(name) {//获取session存储值
    var session = window.sessionStorage;
    var str = JSON.parse(session.getItem(name));
    console.log(str);
    return str;
}

function proRootUrl() {
    var url = basePath + 'product/getPageData' + enddo;
    return url;
}

function stitching_info_url(id) {
    var url = basePath + '/info' + id;
    return url;
}
avalon.filters.src = function (obj) {
    var src = obj.src;
    var newSrc = src.replace('_size', '_origin');
    console.log(newSrc);
    obj.src = newSrc;
    return obj;
}
function pro_detail_url(id) {
    var url = basePath + 'product/getProductInfo'+ enddo+"?id="+id;
    return url;
}

function workPlace_url() {
    var url = basePath + 'dict/findWorkplace'+ enddo;
    return url;
}
function findJobType_url() {
    var url = basePath + 'dict/findJobType'+ enddo;
    return url;
}
function getPageJobs_url() {
    var url = basePath + 'recruitmentJob/getPageJobs'+ enddo;
    return url;
}
function job_detail_url(id) {
    var url = basePath + 'recruitmentJob/getJobDetail'+ enddo+"?id=" + id;
    return url;
}
function resumeApply_url() {
    var url = basePath + 'recruitmentJob/resumeApply'+ enddo+"?";
    return url;
}
function getFindCodeUrl() {
    var url = basePath + 'securityCode/findCode' + enddo;
    return url;
}
function getOrderUrl(orderNo) {
    var url = basePath + 'order/query' + enddo+'?orderNo='+orderNo;
    return url;
}

/*mock.js start*/
function getMockData() {
    Mock.mock(proRootUrl(),
        {
            "menu|3-7": [{
                "menuTitle": Mock.Random.ctitle(5, 10),
                "subMenu|4-8": [{
                    "subTitle": Mock.Random.ctitle(5, 10),
                    "id|+1": 10010
                }]
            }],
            "classify|2-5": [
                {
                    "classifyName": Mock.Random.ctitle(2, 5)
                }
            ],
            "place|2-5": [
                {
                    "placeName": Mock.Random.ctitle(2, 5)
                }
            ],
            "unlock_mode|5-9": [
                {
                    "modeName": Mock.Random.ctitle(2, 4)
                }
            ]
        });
}

function getProData(id) {
    Mock.mock(stitching_info_url(id),
        {
            "product|3-7": [{
                "imgUrl": Mock.Random.image('280x225'),
                "name": Mock.Random.ctitle(16, 30),
                "place|5-8": [Mock.Random.ctitle(4, 5)],
                "color|3": ["古铜色"],
                "id|+1": 100101,
                "style|1-4": [1],
            }]
        });
}

function getProDetailData(id) {
    Mock.mock(pro_detail_url(id),
        {
            "proDetail": [{
                "imgUrl|1-5": [Mock.Random.image('554x554')],
                "comparePro|5": [{
                    "img": Mock.Random.image('180x220'),
                    "name": "智能指纹锁",
                    "price": "￥1099元"
                }],
                "name": Mock.Random.ctitle(16, 30),
                "tips": "当天可发货，指纹门锁，防盗锁",
                "newPrice": "1499.00",
                "oldPrice": "￥1599.00",
                "chooseColour": {
                    "title": "选择颜色",
                    "color|3-6": ["三合一（金色）"],
                },
                "chooseDirect": {
                    "title": "选择方向",
                    "direct": ["左侧开", "右侧开"]
                },
                "promise": "支持7天无理由退货",
                "address": "广东省 深圳市 宝安区 松柏路 南岗第二工业区",
                "proDetail": {
                    "title": "商品详情",
                    "brands": "品牌：ADEL/爱迪尔",
                    "model": "型号：US99",
                    "color": "饰面颜色：三合一(亮金色) 三合一(亮铬色) 三合一(红古铜色) 三合一(咖啡铜色) 四合一(亮金色) 四合一(亮铬色) 四合一(红古铜色) 四合一(咖啡铜色)",
                    "material": "面板及执手材质：锌合金",
                    "power": "电源类型：4节AA电池供电，可使用应急外接电源",
                    "electronic": "电子类型：感应锁  密码锁  指纹锁",
                    "storage": "数据存储类型：离线",
                    "proDetailImg": Mock.Random.image('1200x450'),
                    "vedio": {
                        "url": "",
                        "img": Mock.Random.image('1200x450')
                    }
                },
                "relatedPro": {
                    "title": "相关商品",
                    "proList|5": [{
                        "img": Mock.Random.image('180x220'),
                        "name": "智能指纹锁",
                        "price": "￥1099元"
                    }]
                },
                "topComments": [{
                    "title": "热门评论",
                    "commentsList|0-3": [{
                        "userName": Mock.Random.name(),
                        "time": "2017-6-29 12:00",
                        "labels": ["商品包装好看", "外观漂亮"],
                        "usersay": "第一次购买爱迪尔门锁，质量好的没的说，期望平台能有更多的活动优惠。",
                        "starts": [
                            {
                                "title": "包装",
                                "startList|2-5": [1]
                            },
                            {
                                "title": "外观",
                                "startList|2-5": [1]
                            },
                            {
                                "title": "师傅服务",
                                "startList|2-5": [1]
                            },
                            {
                                "title": "送货速度",
                                "startList|2-5": [1],
                            }
                        ],
                        "thumbnails|1-4": [Mock.Random.image('213x214')]
                    }],
                }]
            }]
        });
}

function getRecruitmentData() {
    Mock.mock(workPlace_url(),
        {
            "recruitment": [{
                "title": Mock.Random.ctitle(4),
                "workPlace": {
                    "title": "工作地点",
                    "placeName|3-5": [Mock.Random.city()]
                },
                "jobCategory": {
                    "title": "职位类别",
                    "jobName|3-7": [Mock.Random.ctitle(4, 5)],
                },
                "job": {
                    "header": [
                        "职位名称",
                        "职位类别",
                        "工作地点",
                        "发布时间"
                    ],
                    "jobList|4-10": [{
                        "name": Mock.Random.ctitle(4, 5),
                        "hot|1": Boolean,
                        "classify": Mock.Random.ctitle(4, 5),
                        "location": Mock.Random.city(),
                        "time": Mock.Random.date(),
                        "id|+1": 20010
                    }]
                }
            }]
        });
}

function getJobDetailMockData(id) {
    Mock.mock(job_detail_url(id),
        {
            "jobDetail": [{
                "jobName": {
                    "title": "职位名称",
                    "jobName": Mock.Random.ctitle(4, 5)
                },
                "workPlace": {
                    "title": "工作地点",
                    "placeName": [Mock.Random.city()]
                },
                "jobCategory": {
                    "title": "职位类别",
                    "jobName": Mock.Random.ctitle(4, 5),
                },
                "channel": {
                    "title": "招聘渠道",
                    "jobChannel|1": ['社会招聘', '校园招聘'],
                },
                "jobDuties": {
                    "title": "工作职责",
                    "dutiesList|3-6": [Mock.Random.ctitle(12, 16)]
                },
                "jobRequirements": {
                    "title": "工作要求",
                    "requirementsList|3-6": [Mock.Random.ctitle(12, 16)]
                }
            }]
        });
}
/*
avalon.component('ms-header', {
    template: '<div class="header"><div class="topNav">\
	<ul>\
	<li><a href="#">爱迪尔商城</a></li>\
	<li><a href="../../page/index/index.html">关于爱迪尔</a></li>\
	<li><a href="">招商直通</a></li>\
	<li><a href="../../page/news/index.html">新闻中心</a></li>\
	<li><a href="../../page/serviceSupport/index.html">服务与支持</a></li>\
	<li><a href="../../page/recruitment/index.html">人才招聘</a></li>\
	<li><a href="#">香港HOH网站</a></li>\
	<li><a href="#">美国IDLK网站</a></li>\
	</ul>\
	</div>\
	<div class="navBar">\
	<div class="navContent">\
	<div class="logo"></div>\
	<ul>\
	<li><a href="#">家庭方案</a></li>\
	<li><a href="">智能密码</a></li>\
	<li><a href="">感应遥控</a></li>\
	<li><a href="">指纹保管箱</a></li>\
	<li><a href="">酒店房卡</a></li>\
	<li><a href="">服务</a></li>\
	</ul>\
	<div class="search">\
	<input type="text" ms-duplex="@search">\
	<div ms-click="@searchPro()"></div>\
	</div>\
	</div>\
	</div></div>',
    defaults: {
        search: '',
        searchPro: function () {
            var self = this;
            ff.util.submit({
                url: 'commodity/searchCommodity',
                data: {
                    title: self.search,
                    page: 1,
                    pageSize: 10
                },
                success: function (res) {
                    var search_data = res.resultData;
                    console.log(JSON.stringify(search_data, null, 4))
                    var url=baseSearchUrl + 'product/productlist.html';
                    var data={
                        searchData:search_data,
                        type:'search',
                        style:self.search
                    }
                    //var key='searchData'
                    ff.page.go(url,data);
                }
            });
        }
    }
});
avalon.component('ms-service', {
    template: '<div><div class="service">\
	<div>\
	<img src="../../asset/images/wx_icon.png" alt="">\
	<p>预约维修服务</p>\
	</div>\
	<div>\
	<img src="../../asset/images/sh_icon.png" alt="">\
	<p>网络售后服务</p>\
	</div>\
	<div>\
	<img src="../../asset/images/sh_icon.png" alt="">\
	<p>网络售后服务</p>\
	</div>\
	<div>\
	<img src="../../asset/images/gz_icon.png" alt="">\
	<p>售后规则1</p>\
	</div>\
	<div>\
	<img src="../../asset/images/gz_icon.png" alt="">\
	<p>售后规则2</p>\
	</div>\
	</div>\
	<div class="business">\
	<dl>\
	<dt>帮助中心</dt>\
	<dd><a href="#">账户管理</a></dd>\
	<dd><a href="#">帮助2</a></dd>\
	<dd><a href="#">帮助3</a></dd>\
	</dl>\
	<dl>\
	<dt>帮助中心</dt>\
	<dd><a href="#">账户管理</a></dd>\
	<dd><a href="#">帮助2</a></dd>\
	<dd><a href="#">帮助3</a></dd>\
	</dl>\
	<dl>\
	<dt>帮助中心</dt>\
	<dd><a href="#">账户管理</a></dd>\
	<dd><a href="#">帮助2</a></dd>\
	<dd><a href="#">帮助3</a></dd>\
	</dl>\
	<dl>\
	<dt>帮助中心</dt>\
	<dd><a href="#">账户管理</a></dd>\
	<dd><a href="#">帮助2</a></dd>\
	<dd><a href="#">帮助3</a></dd>\
	</dl>\
	<dl>\
	<dt>帮助中心</dt>\
	<dd><a href="#">账户管理</a></dd>\
	<dd><a href="#">帮助2</a></dd>\
	<dd><a href="#">帮助3</a></dd>\
	</dl>\
	<dl>\
	<dt>帮助中心</dt>\
	<dd><a href="#">账户管理</a></dd>\
	<dd><a href="#">帮助2</a></dd>\
	<dd><a href="#">帮助3</a></dd>\
	</dl>\
	<ul>\
	<li>40-000-12345</li>\
	<li>周一至周日 8:00-18:00</li>\
<li>（仅收市话费）</li>\
<li><span></span>24小时在线响应</li>\
</ul>\
</div></div>'
})

avalon.component('ms-footer', {
    template: '<div class="footer"> <div> <p>Copyright © 1993-2017 ADEL Group All Rights Reserved    投诉电话:15818669806（以短信为主）工商营业执照注册号：440301103174719    国家信产部ICP经营许可证备案号：粤ICP备13017878</p> <img src="../../asset/images/gswj.png" alt=""> </div> </div>'
})
*/
// function includeLinkStyle(url){
// 	var link = document.createElement("link");
// 	link.rel = "stylesheet";
// 	link.type = "text/css";
// 	link.href = url;
// 	document.getElementsByTagName("head")[0].appendChild(link);
// }

// document.write("<script type='text/javascript' src='../../../../asset/js/vue2.0.3.js'></script>");
// document.write("<script type='text/javascript' src='../../../../asset/js/jquery-2.1.4.js'></script>");
// document.write("<script type='text/javascript' src='../../../../asset/js/jquery-weui.js'></script>");


// includeLinkStyle("../../../../asset/css/loadingAnimate.css")
//includeLinkStyle("../../../../asset/css/jquery-weui.css");
//includeLinkStyle("../../../../asset/css/weui.min.css");


